package com.guli.eduService.controller.front;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guli.commonUtils.R;
import com.guli.eduService.entity.EduCourse;
import com.guli.eduService.entity.EduTeacher;
import com.guli.eduService.service.impl.EduTeacherServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zxc
 * @date 2023/04/18 09:48
 **/
@Api(description = "前台讲师数据展示")
@RestController
@RequestMapping("/eduService/teacherFront")
//@CrossOrigin // 解决跨域问题
public class TeacherFrontController {

    @Autowired
    private EduTeacherServiceImpl teacherService;

    @ApiOperation(value = "分页条件查询获取前台讲师数据")
    @GetMapping("getTeacherInfoCondition/{currentPage}/{limit}")
    public R getTeacherInfoCondition(
            @ApiParam(name = "currentPage" , value = "当前页码" , required = true)
            @PathVariable long currentPage ,

            @ApiParam(name = "limit" , value = "当前页记录数" , required = true)
            @PathVariable long limit){
        Page<EduTeacher> page = new Page<>(currentPage , limit);
        // 根据前端所传递过来的条件，封装成queryWrapper对象，同时将其传递给分页查询方法;
        Map<String , Object> map = teacherService.getFrontTeacherInfoCondition(page);
        return R.ok().data(map);

    }

    @ApiOperation(value = "根据讲师id，来查询讲师基本信息和其所讲课程信息")
    @GetMapping("getTeacherInfoDetails/{teacherId}")
    public R getTeacherInfoDetails(
            @ApiParam(name = "teacherId" , value = "讲师ID" , required = true)
            @PathVariable String teacherId){
        // 查询该讲师所讲的所有课程信息;
        List<EduCourse> course = teacherService.getTeacherCourse(teacherId);
        EduTeacher teacherInfo = teacherService.getById(teacherId);
        Map<String , Object> map = new HashMap<>();
        map.put("teacherInfo" , teacherInfo);
        map.put("courseInfo" , course);
        return R.ok().data(map);

    }

}
